package com.connection.second.wallpaper.service.impl;

import java.util.List;

import com.connection.second.common.constant.Constants;
import com.connection.second.common.constant.UserConstants;
import com.connection.second.common.core.domain.model.LoginUser;
import com.connection.second.common.exception.ServiceException;
import com.connection.second.common.exception.user.BlackListException;
import com.connection.second.common.exception.user.UserNotExistsException;
import com.connection.second.common.exception.user.UserPasswordNotMatchException;
import com.connection.second.common.utils.MessageUtils;
import com.connection.second.common.utils.StringUtils;
import com.connection.second.common.utils.ip.IpUtils;
import com.connection.second.framework.manager.AsyncManager;
import com.connection.second.framework.manager.factory.AsyncFactory;
import com.connection.second.framework.security.context.AuthenticationContextHolder;
import com.connection.second.framework.web.service.SysLoginService;
import com.connection.second.framework.web.service.TokenService;
import com.connection.second.system.service.ISysConfigService;
import com.connection.second.wallpaper.mapper.PaperUserCollectionMapper;
import com.connection.second.wallpaper.mapper.PaperUserPostingMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;
import com.connection.second.wallpaper.mapper.PaperUserInfoMapper;
import com.connection.second.wallpaper.domain.entity.PaperUserInfo;
import com.connection.second.wallpaper.service.IPaperUserInfoService;

import javax.annotation.Resource;

/**
 * 用户管理Service业务层处理
 * 
 * @author FL
 * @date 2024-11-15
 */
@Service
public class PaperUserInfoServiceImpl implements IPaperUserInfoService 
{
    @Autowired
    private PaperUserInfoMapper paperUserInfoMapper;
    @Resource
    private PaperUserPostingMapper paperUserPostingMapper;
    @Resource
    private PaperUserCollectionMapper paperUserCollectionMapper;

    /**
     * 查询用户管理
     * 
     * @param id 用户管理主键
     * @return 用户管理
     */
    @Override
    public PaperUserInfo selectPaperUserInfoById(Long id)
    {
        return paperUserInfoMapper.selectPaperUserInfoById(id);
    }


    /**
     * 查询用户管理列表
     * 
     * @param paperUserInfo 用户管理
     * @return 用户管理
     */
    @Override
    public List<PaperUserInfo> selectPaperUserInfoList(PaperUserInfo paperUserInfo)
    {
        return paperUserInfoMapper.selectPaperUserInfoList(paperUserInfo);
    }

    /**
     * 新增用户管理
     * 
     * @param paperUserInfo 用户管理
     * @return 结果
     */
    @Override
    public int insertPaperUserInfo(PaperUserInfo paperUserInfo)
    {
        return paperUserInfoMapper.insertPaperUserInfo(paperUserInfo);
    }

    /**
     * 修改用户管理
     * 
     * @param paperUserInfo 用户管理
     * @return 结果
     */
    @Override
    public int updatePaperUserInfo(PaperUserInfo paperUserInfo)
    {
        return paperUserInfoMapper.updatePaperUserInfo(paperUserInfo);
    }

    /**
     * 批量删除用户管理
     * 
     * @param ids 需要删除的用户管理主键
     * @return 结果
     */
    @Override
    public int deletePaperUserInfoByIds(Long[] ids)
    {
        return paperUserInfoMapper.deletePaperUserInfoByIds(ids);
    }

    /**
     * 删除用户管理信息
     * 
     * @param id 用户管理主键
     * @return 结果
     */
    @Override
    public int deletePaperUserInfoById(Long id)
    {
        return paperUserInfoMapper.deletePaperUserInfoById(id);
    }

    @Override
    @Cacheable(value = "userInfoCache", key = "#accountId")
    public PaperUserInfo selectPaperUserInfoByAccountId(Long accountId) {
        PaperUserInfo info = paperUserInfoMapper.selectPaperUserInfoByAccountId(accountId);
        if (info == null) {
            return null;
        }
        info.setPublishSize(paperUserPostingMapper.countUserPosting(accountId));
        info.setCollectionSize(paperUserCollectionMapper.countPaperUserCollection(accountId));
        return info;
    }


}
